package com.ruitu.health_2.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_2.mvp.model.VideoModel;
import com.ruitu.health_2.ui.common.VideoDetailActivity;
import com.ruitu.health_2.ui.common.VideoListActivity;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.product.Video;
import com.ruitu.router_module.bean.product.VideoDetial;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class VideoPresenter {

    public static class VideoListP extends BasePresenter<VideoListActivity, VideoModel.VideoListM> {
        public Disposable reqVideoList(int size, int num) {
            return m.reqVideoList(size, num).subscribe(new Consumer<BaseResult2<PageModel2<Video>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<Video>> baseResult) throws Exception {
                    v.hideProgress();
                    if (baseResult.isSuccess()) {
                        v.onReqComplete(1, true, baseResult.getData());
                    } else {
                        ToastUtils.showShortSafe(baseResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    throwable.printStackTrace();
                    v.hideProgress();
                    ToastUtils.showShortSafe("获取视频列表失败");
                }
            });
        }

        public Disposable reqVideoListByTitle(int size, int num, String title) {
            return m.reqVideoListByTitle(size, num, title).subscribe(new Consumer<BaseResult2<PageModel2<Video>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<Video>> baseResult) throws Exception {
                    v.hideProgress();
                    if (baseResult.isSuccess()) {
                        v.onReqComplete(2, true, baseResult.getData());
                    } else {
                        ToastUtils.showShortSafe(baseResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    throwable.printStackTrace();
                    v.hideProgress();
                }
            });
        }

        public Disposable reqVideoListByColumn(String posId, int size, int num) {
            return m.reqVideoListByColumn(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<Video>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<Video>> baseResult) throws Exception {
                    v.hideProgress();
                    if (baseResult.isSuccess()) {
                        v.onReqComplete(2, true, baseResult.getData());
                    } else {
                        ToastUtils.showShortSafe(baseResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    throwable.printStackTrace();
                    v.hideProgress();
                }
            });
        }
    }

    public static class VideoDetailP extends BasePresenter<VideoDetailActivity, VideoModel.VideoDetailM> {
        public Disposable reqVideoDetail(String id, String memberId) {
            return m.reqVideoDetail(id, memberId).subscribe(new Consumer<BaseResult2<VideoDetial>>() {
                @Override
                public void accept(BaseResult2<VideoDetial> baseResult2) throws Exception {
                    v.hideProgress();
                    if (baseResult2.isSuccess()) {
                        v.onReqComplete(1, true, baseResult2.getData());
                    } else {
                        ToastUtils.showShortSafe(baseResult2.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    v.hideProgress();
                    ToastUtils.showShortSafe("获取视频信息失败,请稍后重试");
                    throwable.printStackTrace();
                }
            });
        }
    }
}
